package com.jerry.api.entity;

import lombok.Data;

@Data
public class JBaseResult<T> {
    private int code;
    private String msg;
    private T data;

    public JBaseResult() {
    }

    public JBaseResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static JBaseResult success(String msg) {

        return new JBaseResult(0, msg, null);
    }

    public static <T> JBaseResult<T> success(T object) {
        JBaseResult<T> r = new JBaseResult<T>(0, "success", object);
        r.data = object;
        r.code = 1;
        return r;
    }

    public static <T> JBaseResult<T> fail(String msg) {
        JBaseResult<T> r = new JBaseResult<T>(0, msg, null);
        r.code = 0;
        r.msg = msg;
        return r;
    }

    @Override
    public String toString() {
        return "BaseResult{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}

